package com.eliza.room.db.vm

import android.app.Application
import androidx.lifecycle.AndroidViewModel
import androidx.lifecycle.LiveData
import com.eliza.room.db.dao.StudentRepository
import com.eliza.room.model.Student


/*-*- coding:utf-8 -*-
 * @Author  : debi
 * @Time    : 3/30/22
 * @Software: Android Studio
 */
/*
viewModel  不推荐使用 application
    此处使用 AndroidViewModel
*/
class StudentVm : AndroidViewModel {

    private var repository: StudentRepository


    constructor(application: Application) : super(application) {
        this.repository = StudentRepository(application);
    }

    suspend fun insertStudent(vararg students: Student) {
        repository.insertStudent(*students)
    }

    suspend fun deleteStudent(vararg students: Student) {
        repository.deleteStudent(*students)
    }


    suspend fun updateStudent(vararg students: Student) {
        repository.updateStudent(*students)
    }

    fun getAllStudentsLive(): LiveData<List<Student>> {

        return repository.allStudentsLive
    }
}